﻿using BCCommon;
using BCCommon.Enums;
using BCDto.Website.User;
using BCDto.WeChatComponent.WeChatUser;
using BCService.Website.User;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Mvc;
using System;

namespace BCTMSRESTful.Controllers.Management.User
{
    /// <summary>
    /// 用户控制器
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class UserController : ManagementBaseController
    {
        private readonly IUserService userService;

        public UserController(IUserService userService)
        {
            this.userService = userService;
        }

        #region 获取用戶信息列表（分页）
        /// <summary>
        /// 获取用戶信息列表（分页）。
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="phone">手机号</param>
        /// <param name="identityCardNo">身份证编码</param>
        /// <param name="accountStatus">账号状态</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="ascending">排序</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取用戶信息列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(PageableList<WeChatUserInfoDto>), 200)]
        public IActionResult Get([FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            [FromQuery(Name = "phone")] string phone,
            [FromQuery(Name = "user_name")] string userName,
            [FromQuery(Name = "account_status")] AccountStatus? accountStatus,
            [FromQuery(Name = "identity_card_no")] string identityCardNo,
            [FromQuery(Name = "ascending")] bool? ascending,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            return this.Ok(this.userService.GetUserList(userName, phone, identityCardNo, accountStatus, RoleType.User, start, end, ascending, pageIndex, pageSize));
        }
        #endregion

        #region 获取用户信息
        /// <summary>
        /// 获取用户信息。
        /// </summary>
        /// <param name="userId">用户名</param>
        /// <response code="200">用戶信息</response>
        /// <returns></returns>
        [HttpGet("{user_id}")]
        [ProducesResponseType(typeof(UserDto), 200)]
        public IActionResult Put([FromRoute(Name = "user_id")] long userId)
        {
            return this.Ok(this.userService.GetUserByUserId(userId));
        }
        #endregion

        #region 实名认证审核
        /// <summary>
        /// 实名认证审核通过
        /// </summary>
        /// <param name="userId">用户Id</param>
        /// <param name="dto">审核信息</param>
        /// <returns></returns>
        /// <response code="200">实名认证审核成功。</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="401">请求需要认证或者认证信息已过期。</response>
        /// <response code="500">服务器内部错误。</response>
        [HttpPost("[action]/{user_id}")]
        [Log("实名认证审核")]
        [ProducesResponseType(typeof(UserDto), 200)]
        public IActionResult RealNameVerifiesApprove([FromRoute(Name = "user_id")] long userId, [FromBody] UserApproveRequestDto dto)
        {
            return Ok(userService.RealNameVerifiesApprove(this.Admin, userId, dto));
        }
        #endregion
    }
}
